package DTO;

import java.util.Vector;

import XML.XMLHelper;

public class Table {
	private String 			_databaseName;
	private String 			_Name;
	private Vector<Field> 	_Fields;
	private Vector<Row> 	_Rows;
		
	public String get_Name() {
		return _Name;
	} 
	public void set_Name(String _Name) {
		this._Name = _Name;
	}
	public Vector<Field> get_Fields() {
		return _Fields;
	}
	public void set_Fields(Vector<Field> _Fields) {
		if(_Fields == null)
			_Fields = new Vector<Field>();
		
		this._Fields = _Fields;
	}
	public Vector<Row> get_Rows() {
		return _Rows;
	}
	public void set_Row(Vector<Row> _Rows) {
		if(_Rows == null)
			_Rows = new Vector<Row>();
		this._Rows = _Rows;
	}
	
	//Contructor
	public Table(String name, String databaseName, Vector<Field> fields, Vector<Row> rows)
	{
		this.set_Fields(fields);
		this.set_Name(name);		
		this.set_Row(rows);
		this.set_databaseName(databaseName);
		//XMLHelper.CreateTableStructure(databaseName, name, fields);
	}	
	
	public String get_databaseName() {
		return _databaseName;
	}
	public void set_databaseName(String _databaseName) {
		this._databaseName = _databaseName;
	}
	
	/**
	 * Insert new row to database. Use XMLHelper.InsertRow
	 * @param row New row need to add
	 * @return 
	 * Return true if it added success!
	 * Return false if it added failed!
	 */
	public boolean insertRow(Row row)
	{
		boolean ret = false;
		
		
		return ret;
	}
	
	/**
	 * @param fieldsToUpdate
	 * @param valsToUpdate
	 * @param conditionFeilds
	 * @param conditionVals
	 * @return
	 */
	public boolean updateRow(Vector<String> fieldsToUpdate, Vector<Object> valsToUpdate,
			Vector<String> conditionFeilds, Vector<Object> conditionVals)
	{	
		boolean res = false;
		
		return res;
	}
	
	/**
	 * Insert new row to database. Use XMLHelper.InsertRow
	 * @param row New row need to deletex
	 * @return
	 * Return true if it deleted success!
	 * Return false if it deleted failed!
	 */
	public boolean deleteRow(Row row)
	{
		boolean ret = false;
		
		return ret;
	}
	// IO
	
	/**
	 * Load table struct and table data from file. 
	 * If this Table doesn't have name or doesn't have database'name, this 
	 * function will fail!
	 */
	public void load()
	{
		Vector<Field> fields = XMLHelper.GetListOfField(this.get_databaseName(), this.get_Name());
		Vector<Row>rows = XMLHelper.GetListOfRow(this.get_databaseName(), this.get_Name());
		this.set_Fields(fields);
		this.set_Row(rows);
	}
	
	/**
	 * (Chua hoan thanh)
	 * Save table struct and table data to file. 
	 * If file exists, only change data of file
	 * If none, create struct file and data file and save it data to 2 files which created.
	 */
	public void save()
	{
		
	}

}
